package userlogic

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/login-rpc/internal/dao/model"
	"gitee.com/liuxuezhan/ar-platform/login-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/login-rpc/login_rpc"
	config "gitee.com/liuxuezhan/ar-platform/login-rpc/pkg/code"

	"github.com/zeromicro/go-zero/core/logx"
)

type ResetGoogleLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewResetGoogleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ResetGoogleLogic {
	return &ResetGoogleLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ResetGoogleLogic) ResetGoogle(in *login_rpc.ResetGoogleRequest) (*login_rpc.ResetGoogleResponse, error) {
	var commonResp login_rpc.CommonResp
	// 更新到数据库
	err := model.NewAdminUserModel(l.ctx, l.svcCtx.Db).ResetGoogleCode(in.UserId)
	if err != nil {
		commonResp.Code = config.DBError
		commonResp.Message = "update failed"
		return &login_rpc.ResetGoogleResponse{CommonResp: &commonResp}, nil
	}
	return &login_rpc.ResetGoogleResponse{CommonResp: &commonResp}, nil
}
